package com.suptracking.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.suptracking.entity.Car;
import com.suptracking.entity.User;
import com.suptracking.service.CarService;
import com.suptracking.service.UserService;

/**
 * Servlet implementation class IndexServlet
 */
@WebServlet("/index")
public class IndexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@EJB
	private UserService userservice;

	@EJB
	private CarService carservice;
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	//Pour tout type de user
		Long _usercount = userservice.getNumberOfUser();
		Long _carcount = carservice.getNumberOfCarService();
		request.setAttribute("UserCount", _usercount);
		request.setAttribute("CarCount", _carcount);
	//Pour auth Only
		HttpSession Session= request.getSession();
		User usersession =(User) Session.getAttribute("User");
		if(usersession != null){
			List<Car> _carlist = usersession.getCar();
			request.setAttribute("CarList", _carlist);
			
		}
		
		
		
		request.getRequestDispatcher("/index.jsp").forward(request, response);
		
	}


}
